package com.devicemantra.coordinate.ds.tests;
import com.devicemantra.coordinate.dataobjects.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.*;

import com.devicemantra.coordinate.dataobjects.CDepartmentFactory;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.datastore.Query;

@SuppressWarnings("serial")
public class FilterFrame extends HttpServlet 
{
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException 
	{
		resp.setContentType("text/html");
		PersistenceManager pm = PMF.get().getPersistenceManager();
		/* Check whether a department exists with the same name */
		javax.jdo.Query q = pm.newQuery("select mMappedDepartment from " + CLocation.class.getName() + " where mMappedDepartment.getDepartmentName() == \"COMPUTER SCIENCE\"");
	    List ids = (List) q.execute();
	    resp.getOutputStream().print("Size of list is " + ids.size());
	    /*Iterator<Key> lIterKeys = ids.iterator();
	    while( lIterKeys.hasNext())
	    {
	    	Key lKey = (Key) lIterKeys.next();
	    	Key lParentKey = lKey.getParent();
	    	//resp.getOutputStream().print("<BR> Child is " + KeyFactory.keyToString(lKey));
	    	//resp.getOutputStream().print(" for parent - " + KeyFactory.keyToString(lParentKey) + "<BR>");
	    	
	    	CLocation lLoc = pm.getObjectById(CLocation.class,lKey);
	    	CFrame lFrame = pm.getObjectById(CFrame.class,lParentKey);
	    	lFrame = pm.detachCopy(lFrame);
	    	resp.getOutputStream().print("Frame AT  - (" + lLoc.getLatitude() + "," + lLoc.getLongitude() + ") "+ lFrame.getFrameDescription() + "Owned by "   + lFrame.getOwningDepartment()  + "<BR>");
	    } */
	    pm.close();
		//resp.getOutputStream().print("Frame Added " );
	}
}
